﻿<phone:PhoneApplicationPage
    x:Name="MainPageView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:vm="clr-namespace:DebIt.ViewModel"
    xmlns:uc="clr-namespace:DebIt.View.UserControls"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:ec="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions"
    xmlns:Controls="clr-namespace:Phone7.Fx.Controls;assembly=Phone7.Fx" x:Class="DebIt.View.MainPage"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
    SupportedOrientations="Portrait"  Orientation="Portrait"
    shell:SystemTray.IsVisible="True">
    <UserControl.DataContext>
        <vm:MainPageViewModel/>
    </UserControl.DataContext>

    <phone:PhoneApplicationPage.Resources>
        <Style x:Key="containerStyle" TargetType="ListBoxItem">
            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        </Style>
    </phone:PhoneApplicationPage.Resources>


    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="pMain" Background="Transparent">
        <!--Pivot Control-->
        <controls:Pivot x:Name="pcMain" Title="{Binding LocalizedResources.appName, Source={StaticResource LocalizedStrings}}">
            <!--Pivot item overview-->
            <!--<controls:PivotItem x:Name="piOverview" Header="{Binding LocalizedResources.pi_title_overview, Source={StaticResource LocalizedStrings}}">
                <ListBox ItemContainerStyle="{StaticResource containerStyle}"/>
            </controls:PivotItem>-->

            <!--Pivot item loan-->
            <controls:PivotItem x:Name="piLoan" Header="{Binding LocalizedResources.pi_title_loans, Source={StaticResource LocalizedStrings}}">
                <ListBox ItemsSource="{Binding Loans}" Margin="8,0" ItemContainerStyle="{StaticResource containerStyle}">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <uc:LoanControl LoanSource="{Binding}"  
                                                DeletLoanCommand="{Binding ElementName=MainPageView, Path=DataContext.DeleteLoanCommand}"
                                                LoanPaiedChange="{Binding ElementName=MainPageView, Path=DataContext.IsPaiedChangedCommand}"
                                                EditPageNavigationSource="/View\LoanEdit.xaml"/>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </controls:PivotItem>

            <!--Pivot item client-->
            <controls:PivotItem x:Name="piClient" Header="{Binding LocalizedResources.pi_title_clients, Source={StaticResource LocalizedStrings}}">
                <ListBox ItemsSource="{Binding Clients}" Margin="8,0" ItemContainerStyle="{StaticResource containerStyle}">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <uc:ClientControl ClientSource="{Binding}" 
                                                       DeleteClientCommand="{Binding ElementName=MainPageView, Path=DataContext.DeleteClientCommand}" 
                                                       LoanPaiedChange="{Binding ElementName=MainPageView, Path=DataContext.IsPaiedChangedCommand}"
                                                       EditPageNavigationSource="/View\ClientEdit.xaml"/>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </controls:PivotItem>

        </controls:Pivot>
        <Controls:BindableApplicationBar IsVisible="True" IsMenuEnabled="True" x:Name="apMain">
            <!--<Controls:BindableApplicationBarIconButton IconUri="/icons/undo.png" Text="{Binding Path=LocalizedResources.st_pivot_undo, Source={StaticResource LocalizedStrings}}"/>
            <Controls:BindableApplicationBarIconButton IconUri="/icons/redo.png" Text="{Binding Path=LocalizedResources.st_pivot_redo, Source={StaticResource LocalizedStrings}}"/>-->
            <Controls:BindableApplicationBarIconButton IconUri="/icons/dark/questionmark.png" Text="{Binding Path=LocalizedResources.st_tb_about, Source={StaticResource LocalizedStrings}}">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <ec:NavigateToPageAction TargetPage="/View\AboutView.xaml"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Controls:BindableApplicationBarIconButton>
            <Controls:BindableApplicationBar.MenuItems>
                <Controls:BindableApplicationBarMenuItem x:Name="menuItem2" Text="{Binding Path=LocalizedResources.na_new_loan, Source={StaticResource LocalizedStrings}}">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="Click">
                            <ec:NavigateToPageAction TargetPage="/View\LoanEdit.xaml"/>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </Controls:BindableApplicationBarMenuItem>
                <Controls:BindableApplicationBarMenuItem x:Name="menuItem1" Text="{Binding Path=LocalizedResources.na_new_client, Source={StaticResource LocalizedStrings}}">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="Click">
                            <ec:NavigateToPageAction TargetPage="/View\ClientEdit.xaml"/>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </Controls:BindableApplicationBarMenuItem>
            </Controls:BindableApplicationBar.MenuItems>
        </Controls:BindableApplicationBar>
    </Grid>



</phone:PhoneApplicationPage>